export default class RowEditorService {
    context;
    constructor(context) {
        this.context = context;
    }
    openSetTag(type, isHiddenModal) {
        const coords = this.context.gridRef.state.currentRecord?.coords;
        if (!coords) {
            this.context.showErrorNotify("请选择单元格进行操作");
            return;
        }
        let defaultTagType = this.context.state.tagType;
        if (type === "column") {
            defaultTagType = "column";
        }
        //获取当前行的聚合标签.
        if (defaultTagType === "row" && coords.row > -1) {
            const cellMeta = this.context.hot.getCellMeta(coords.row, 1);
            const tags = cellMeta.r_tag;
            const all_rows_tags = this.context.tagService.getAllTag("row");
            let newsTags = [];
            if (tags && tags.length) {
                newsTags =
                    tags &&
                        tags.filter(function (tag) {
                            return !tag.includes("TOP--");
                        });
            }
            console.log("--------------tag------------", tags);
            this.context.setState(() => ({
                allRowTags: all_rows_tags,
                currentRowTags: newsTags ? newsTags : [],
            }));
        }
        //获取当前列的聚合标签
        if (defaultTagType === "column" && coords.col > -1) {
            const rowIndex = coords.row < 0 ? 0 : coords.row; //如果选中的是列头，那么就默认取第一行的坐标。为了兼容下面写的逻辑.因为列标签只存储在列配置上,行坐标意义不大.
            const cellMeta = this.context.hot.getCellMeta(rowIndex, coords.col);
            const all_column_tags = this.context.tagService.getAllTag("column");
            const tags = cellMeta.c_tag;
            let newsTags = [];
            if (tags && tags.length) {
                newsTags =
                    tags &&
                        tags.filter(function (tag) {
                            return !tag.includes("LEFT--");
                        });
            }
            console.log("--------------tag------------", tags);
            this.context.setState({
                allColumnTags: all_column_tags,
                currentColumnTags: newsTags || [],
            });
        }
        this.context.setState(() => ({
            tagType: type,
            isOpenSetTag: isHiddenModal ? false : true,
        }));
    }
}
